package com.resafety.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.resafety.springcloud.service.FeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
//全局指定默认异常方法
@DefaultProperties(defaultFallback = "error")
public class feignController {
    @Resource
    private FeignService feignService;

    @GetMapping("feign/ok/{id}")
    public String feignok(@PathVariable("id")Integer id){
        return feignService.Payment_OK(id);
    }

    @GetMapping("feign/timeout/{id}")
    @HystrixCommand
//    @HystrixCommand(fallbackMethod = "error",commandProperties = {
//            //设置这个线程的超时时间是3s，3s内是正常的业务逻辑，超过3s调用fallbackMethod指定的方法进行处理
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
//    })
    public String feigntimeout(@PathVariable("id")Integer id){
        return feignService.Payment_timeout(id);
    }

    public String error(){
        return "失败80";
    }
}
